package io.renren.modules.medical.controller;

import com.alibaba.fastjson.JSONObject;
import io.renren.common.result.Result;
import io.renren.modules.medical.service.RemoteService;
import io.renren.modules.medical.to.RemoteFormTo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;


/**
 * 远程数据分析接口
 * @author Luo Sheng
 * @school YiBin university
 * @create 2023-02-21 19:49
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/remote")
public class RemoteController {

    private final RemoteService remoteService;

    /**
     * 获取诊断
     */
    @GetMapping("/getDiagnose")
    public Result<String> getDiagnose(@RequestBody(required = false) RemoteFormTo remoteFormTo){
        RemoteFormTo remoteForm = new RemoteFormTo();
        remoteForm.setName("小明");
        remoteForm.setAge(13);
        remoteForm.setTitle("膝盖总是疼痛");
        String jsonString = JSONObject.toJSONString(remoteForm);
        // 获取运行环境钟的resource真实绝对路径
        String classesPath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("")).getPath(); //注意getResource("")里面是空字符串
        log.info("classesPath：{}",classesPath);
        remoteService.executePyScript(classesPath); // 先调用线程执行
        String result = remoteService.RemoteCall(jsonString);
        System.out.println("返回结果：" + result);
        return Result.success(result);
    }

    @GetMapping("/getPicture")
    public Result<String> getPicture(@RequestBody(required = false) RemoteFormTo remoteFormTo){
        return Result.success(null);
    }
}
